/**
 * Created with JetBrains WebStorm.
 * User: Administrator
 * Date: 7/6/12
 * Time: 5:28 AM
 * To change this template use File | Settings | File Templates.
 */

g_xImage = new Image();
g_oImage = new Image();
g_bkImage = new Image();

// bind to window event
window.addEventListener('load', onLoadHandler, false);

/**
 * Global window onload handler
 */
function onLoadHandler()
{
    GameHandler.init(400, 32);
    GameHandler.start(new TickTacToe.Main());
}

/**
 * TickTacToe root namespace
 */
if (typeof TickTacToe == "undefined" || !TickTacToe)
{
    var TickTacToe = {};
}

/**
 * TickTacToe main game class
 *
 * @namespace TickTacToe
 * @class TickTacToe.Main
 */
(function(){
    TickTacToe.Main = function()
    {
        var loadingScreen = new TickTacToe.LoadingScene(this);
        this.curScene = loadingScreen;
        var loader = new Game.Preloader();
        loader.addImage(g_xImage, 'images/icon-x.png');
        loader.addImage(g_oImage, 'images/icon-o.png');
        loader.addImage(g_bkImage, 'images/background_game.png');
        TickTacToe.Main.superclass.constructor.call(this);
        loader.onLoadCallback(function() {
            loadingScreen.Ready();
        });
     };

    // inherited from Game.Main
    extend (TickTacToe.Main, Game.Main,
    {
        onRenderGame: function onRenderGame(ctx)
        {
            ctx.clearRect(0, 0, GameHandler.width, GameHandler.height);
            this.curScene.onRenderScene(ctx);
        },

        isGamePaused: function isGamePaused(ctx){

        },

        isGameOver: function isGameOver()
        {
            var over = (!this.player.alive && (this.currentScene.effects && this.currentScene.effects.length === 0));
            if (over)
            {
                // reset player ready for game restart
                this.lastscore = this.score;
                this.score = 0;
                this.scoreMultiplier = 1;
            }
            return over;
        }
    });
})();




